puts CFLAGS = "#{ENV['CFLAGS'] || ""} #{`sdl-config --cflags`.strip} -I#{Config::CONFIG['archdir']} -IChipmunk"
puts LDFLAGS = "#{ENV['LDFLAGS'] || ""} #{`sdl-config --libs`.strip} -lpng -ljpeg -lGL -lGLU -lruby -logg -lopenal -lvorbis -lvorbisfile"

aerosol_files = FileList['*.c'].ext('.o') - ['AS_rigid.o']

rule '.o' => '.c' do |t|
  sh "gcc -O3 -ffast-math #{CFLAGS} #{t.source} -c -o #{t.name}"
end

chipmunk_files = FileList['Chipmunk/cp*.c', 'Chipmunk/rb_cp*.c', 'Chipmunk/chipmunk.c', 'Chipmunk/rb_chipmunk.c'].ext('.o')
multitask :chipmunk => chipmunk_files

multitask :aerosol => aerosol_files + [:chipmunk]

file 'Game/aerosol' => :aerosol do
  object_files = FileList['*.o', 'Chipmunk/*.o']
  sh "gcc #{LDFLAGS} #{object_files} -o Game/aerosol"
end

task :default => 'Game/aerosol'

task :clean do
  sh 'rm -f Chipmunk/*.o'
  sh 'rm -f *.o'
  sh 'rm -f Game/aerosol'
end

task :docs do
  sh 'rm -rf doc'
  sh 'rdoc documentation.rb lib/Aerosol/*.rb Chipmunk/doc_dummy.rb'
end
